package com.woyowodaows.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.woyowodaows.R;

/**
 * 一个确定按钮弹出框
 */

public class ConfirmOneButtonDialog {

    private Context mContext;
    public Dialog dialog;
    public TextView tvTitles;
    private Button btnSubmit;
    public ImageView ivCancel;

    public ConfirmOneButtonDialog(Context context) {
        this.mContext = context;
        initDialog();
    }
    public void setTitileAndButtonName(String titleName,String ButtonName){
        if (titleName != null && ButtonName!=null) {
            tvTitles.setText(titleName);
            btnSubmit.setText(ButtonName);
        }
    }


    private void initDialog() {
        dialog = new Dialog(mContext, R.style.dialog);
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(false);
        Window window = dialog.getWindow();
        window.setContentView(R.layout.dialog_one_confirm_button);
        ivCancel = (ImageView) window.findViewById(R.id.iv_cancel);
        btnSubmit = (Button) window.findViewById(R.id.btn_submit);
        tvTitles=(TextView)window.findViewById(R.id.tv_titles);
        ivCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismissDialog();
            }
        });
        btnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sumbitAudit();
            }
        });
    }

    private void sumbitAudit() {



        if (onOneButtonListener != null){
            onOneButtonListener.onConfirmButton();
        }

        dismissDialog();

    }



    /**
     * 显示dialog
     */
    public void showDialog() {
        if (dialog != null)
            dialog.show();
    }

    /**
     * 关闭dialog
     */
    public void dismissDialog() {
        if (dialog != null)
            dialog.dismiss();
    }

    public interface   OnOneButtonListener{
        void onConfirmButton();
    }

    private OnOneButtonListener onOneButtonListener;

    public void setOneButtonListener( OnOneButtonListener onOneButtonListener) {
        this.onOneButtonListener = onOneButtonListener;
    }
}
